using UnityEngine;

//立方体生成区域
public class CubeSpawnZone : SpawnZone
{
    [SerializeField]
    bool surfaceOnly;

    public override Vector3 SpawnPoint{
        get{
            //构造立方体随机点
            Vector3 p;
            p.x = Random.Range(-0.5f, 0.5f);
            p.y = Random.Range(-0.5f, 0.5f);
            p.z = Random.Range(-0.5f, 0.5f);
            if(surfaceOnly){
                int axis = Random.Range(0, 3);//可以是用索引来访问vector3的值，
                p[axis] = p[axis] < 0f ? -0.5f : 0.5f;//设置分量到面上
            }
            return transform.TransformPoint(p);
        }
    }

    void OnDrawGizmos()
    {//辅助线
        Gizmos.color = Color.cyan;
        Gizmos.matrix = transform.localToWorldMatrix;
        Gizmos.DrawWireCube(Vector3.zero,Vector3.one);
    }
}